package ta;

import ta.structure.TALocation;
import ta.structure.TATransition;

public class TALayoutHelper
{
    public static final int START_CORD_X = 8;
    public static final int STANDARD_CORD_Y = 8;
    public static final int STANDARD_OFFSET_Y = 100;
    public static final int STANDARD_OFFSET_X = 200;
    // tag pos = (from + to)/2;
    public static final int LABEL_SELECT_Y = -20;
    public static final int LABEL_GUARD_Y = -36;
    public static final int LABEL_SYNC_Y = 16;
    public static final int LABEL_UPDATE_Y = 32;
    public static final int LABEL_NAME_Y = -36;

    private int ptrX;
    private int ptrY;

    public TALayoutHelper()
    {
        reset();
    }

    public void reset()
    {
        ptrX = START_CORD_X;
        ptrY = STANDARD_CORD_Y - STANDARD_OFFSET_Y;
    }

    public void reset(TALocation loc)
    {
        ptrX = loc.x;
        ptrY = loc.y;
    }

    public void next()
    {
        ptrX += STANDARD_OFFSET_X;
        ptrY = STANDARD_CORD_Y - STANDARD_OFFSET_Y;
    }

    public void layoutLocation(TALocation prev, TALocation cur)
    {
        layoutLocation(prev, cur, 0);
    }

    public void layoutLocation(TALocation prev, TALocation cur, int offset_y)
    {
        cur.x = prev.x + STANDARD_OFFSET_X;
        cur.y = prev.y + offset_y * STANDARD_OFFSET_Y;
    }

    public void layoutLocation(TALocation cur)
    {
        ptrY += STANDARD_OFFSET_Y;
        cur.x = ptrX;
        cur.y = ptrY;
    }

    public void layoutTransition(TATransition cur, TALocation from, TALocation to)
    {
        if (from.equals(to))
        {
            cur.x = from.x;
            cur.y = from.y - 80;
        }
        else
        {
            cur.x = (to.x - from.x) / 8 + from.x;
            cur.y = (to.y - from.y) / 8 + from.y;
        }

    }
}
